{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Widest Vertical Area Between Two Points Containing No Points"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Medium"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #sorting"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #排序"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: maxWidthOfVerticalArea"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #两点之间不包含任何点的最宽垂直区域"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你&nbsp;<code>n</code>&nbsp;个二维平面上的点 <code>points</code> ，其中&nbsp;<code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>&nbsp;，请你返回两点之间内部不包含任何点的&nbsp;<strong>最宽垂直区域</strong> 的宽度。</p>\n",
    "\n",
    "<p><strong>垂直区域</strong> 的定义是固定宽度，而 y 轴上无限延伸的一块区域（也就是高度为无穷大）。 <strong>最宽垂直区域</strong> 为宽度最大的一个垂直区域。</p>\n",
    "\n",
    "<p>请注意，垂直区域&nbsp;<strong>边上</strong>&nbsp;的点&nbsp;<strong>不在</strong>&nbsp;区域内。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "<img alt=\"\" src=\"https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/10/31/points3.png\" style=\"width: 276px; height: 371px;\" />​\n",
    "<pre>\n",
    "<b>输入：</b>points = [[8,7],[9,9],[7,4],[9,7]]\n",
    "<b>输出：</b>1\n",
    "<b>解释：</b>红色区域和蓝色区域都是最优区域。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<b>输入：</b>points = [[3,1],[9,0],[1,0],[1,4],[5,3],[8,8]]\n",
    "<b>输出：</b>3\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>n == points.length</code></li>\n",
    "\t<li><code>2 &lt;= n &lt;= 10<sup>5</sup></code></li>\n",
    "\t<li><code>points[i].length == 2</code></li>\n",
    "\t<li><code>0 &lt;= x<sub>i</sub>, y<sub>i</sub>&nbsp;&lt;= 10<sup>9</sup></code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [widest-vertical-area-between-two-points-containing-no-points](https://leetcode.cn/problems/widest-vertical-area-between-two-points-containing-no-points/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [widest-vertical-area-between-two-points-containing-no-points](https://leetcode.cn/problems/widest-vertical-area-between-two-points-containing-no-points/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[[8,7],[9,9],[7,4],[9,7]]', '[[3,1],[9,0],[1,0],[1,4],[5,3],[8,8]]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        sp = sorted(points, key=lambda r: r[0])\n",
    "        ans = 0\n",
    "        for i in range(1, len(points)):\n",
    "            ans = max(ans, sp[i][0]-sp[i-1][0])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        t = sorted(points, key=lambda x: x[0])\n",
    "        ans = -inf\n",
    "        for i in range(0, len(t)-1):\n",
    "            ans = max(t[i+1][0]-t[i][0], ans)\n",
    "        return ans   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        points = sorted(points, key = lambda x:x[0])\n",
    "        ans = 0\n",
    "        for i in range(1, len(points)):\n",
    "            ans = max(ans, points[i][0] - points[i - 1][0])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        points.sort()\n",
    "        mx = 0\n",
    "        for i in range(1, len(points)):\n",
    "            mx = max(points[i][0] - points[i - 1][0], mx)\n",
    "        return mx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        points = sorted(points,key=lambda x:x[0])\n",
    "        max_d = 0\n",
    "        n = len(points)\n",
    "        for i in range(n-1):\n",
    "            max_d = max(points[i+1][0]-points[i][0],max_d)\n",
    "        return max_d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        points.sort()\n",
    "        max = 0\n",
    "        for index in range(1,len(points)):\n",
    "            temp = points[index][0] - points[index - 1][0]\n",
    "            if(temp >max):\n",
    "                max = temp\n",
    "        \n",
    "        return max"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        points.sort()\n",
    "        ans = 0\n",
    "        for i in range(1, len(points)):\n",
    "            ans = max(ans, points[i][0] - points[i - 1][0])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        points.sort(key=lambda x:x[0])\n",
    "        res = [points[i][0]-points[i-1][0] for i in range(1, len(points))]\n",
    "        return max(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        x=0\n",
    "        d=[]\n",
    "        points.sort()\n",
    "        for i in range(1,len(points)):\n",
    "            t=points[i][0]-points[i-1][0]\n",
    "            d.append(t)\n",
    "        x=max(d)\n",
    "        return x\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        points.sort(key=lambda x: x[0])\n",
    "        ma = 0\n",
    "        for index in range(1,len(points)):\n",
    "            ma = max(points[index][0] - points[index - 1][0], ma)\n",
    "           \n",
    "        return ma"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        points.sort()\n",
    "        mx = 0\n",
    "        for i in range(1, len(points)):\n",
    "            mx = max(points[i][0] - points[i - 1][0], mx)\n",
    "        return mx\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        points.sort()\n",
    "        mx = 0\n",
    "        for i in range(1, len(points)):\n",
    "            mx = max(points[i][0] - points[i - 1][0], mx)\n",
    "        return mx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        points.sort()\n",
    "        \n",
    "        mx = 0\n",
    "\n",
    "        for i in range(1, len(points)):\n",
    "            mx = max(points[i][0] - points[i-1][0], mx)\n",
    "        \n",
    "        return mx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        ans = 0\n",
    "        points.sort()\n",
    "        n = len(points)\n",
    "        if n <2:\n",
    "            return 0\n",
    "        for i in range(1,n):\n",
    "            ans = max(ans,points[i][0]-points[i-1][0])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        num=len(points)\n",
    "        points.sort()\n",
    "        mx=0\n",
    "        for i in range(1,num):\n",
    "            mx=max(points[i][0]-points[i-1][0],mx)\n",
    "        return mx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        points.sort(key=lambda x:x[0])\n",
    "        return max(b[0]-a[0] for a, b in pairwise(points))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        points.sort()\n",
    "        res=0\n",
    "        for i in range(1,len(points)):\n",
    "            res=max(res,points[i][0]-points[i-1][0])\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        x=0\n",
    "        d=[]\n",
    "        points.sort()\n",
    "        for i in range(len(points)):\n",
    "            if i>0:\n",
    "                t=points[i][0]-points[i-1][0]\n",
    "                d.append(t)\n",
    "        x=max(d)\n",
    "        return x\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        lst1=[]\n",
    "        for i in points:\n",
    "            lst1.append(i[0])\n",
    "        lst2=sorted(lst1)\n",
    "        lst3=[]\n",
    "        if len(lst2)==1:\n",
    "            return 0\n",
    "        else:\n",
    "            for i in range(1,len(lst2)):\n",
    "                num=lst2[i]-lst2[i-1]\n",
    "                lst3.append(num)\n",
    "            return max(lst3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        points.sort(key=lambda x: x[0])\n",
    "        max = 0\n",
    "        for index in range(1,len(points)):\n",
    "            temp = points[index][0] - points[index - 1][0]\n",
    "            if(temp >max):\n",
    "                max = temp\n",
    "        \n",
    "        return max"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        num = []\n",
    "        for i in range(len(points)):\n",
    "            num.append(points[i][0])\n",
    "        num.sort()\n",
    "        max1 = 0\n",
    "        for i in range(len(num)-1):\n",
    "            max1 = max(max1, num[i+1] - num[i])\n",
    "        return max1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        ans=0\n",
    "        n=len(points)\n",
    "        points.sort(key=lambda x:x[0])\n",
    "        for i in range(n-1):\n",
    "            if points[i+1][0]!=points[i][0]:\n",
    "                ans=max(ans,points[i+1][0]-points[i][0])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        points.sort()\n",
    "        width = 0\n",
    "        pre = points[0][0]\n",
    "        n = len(points)\n",
    "        for i in range(1, n):\n",
    "            if points[i][0] != pre:\n",
    "                width = max(width, points[i][0]-pre)\n",
    "                # print(width)\n",
    "                pre = points[i][0]\n",
    "        return width"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        points.sort()\n",
    "        return max(x2 - x1 for (x1, _), (x2, _) in pairwise(points))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: list[list[int]]) -> int:\n",
    "        tmp=[]\n",
    "        for i in range(len(points)):\n",
    "            tmp.append(points[i][0])\n",
    "        tmp.sort()\n",
    "        max=0\n",
    "        for i in range(len(tmp)-1):\n",
    "            if tmp[i+1]-tmp[i]>max:\n",
    "                max=tmp[i+1]-tmp[i]\n",
    "        return max"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        x=0\n",
    "        d=[]\n",
    "        points.sort()\n",
    "        for i in range(1,len(points)):\n",
    "            x=max(points[i][0]-points[i-1][0],x)\n",
    "        return x\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        return max([b-a for a, b in pairwise(sorted([x for x, _ in points]))])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        num = []\n",
    "        for i in range(len(points)):\n",
    "            num.append(points[i][0])\n",
    "        num.sort()\n",
    "        max1 = 0\n",
    "        for i in range(len(num)-1):\n",
    "            max1 = max(max1, num[i+1] - num[i])\n",
    "        return max1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        nums = [p[0] for p in points]\n",
    "        nums.sort()\n",
    "        mx = 0\n",
    "\n",
    "        for i in range(1, len(nums)):\n",
    "            mx = max(nums[i] - nums[i - 1], mx)\n",
    "        \n",
    "        return mx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        points.sort()\n",
    "        return max(points[i][0]-points[i-1][0] for i in range(1,len(points)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        points.sort()\n",
    "        n = len(points)\n",
    "        M = 0\n",
    "        for i in range(n - 1):\n",
    "            M = max(points[i + 1][0] - points[i][0], M)\n",
    "        return M"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        points.sort()\n",
    "        mx = 0\n",
    "        for i in range(1, len(points)):\n",
    "            mx = max(points[i][0] - points[i - 1][0], mx)\n",
    "        return mx\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        lst=[i[0] for i in points]\n",
    "        lst.sort()\n",
    "        m=0\n",
    "        for i in range(0,len(lst)-1):\n",
    "            m=max(m,lst[i+1]-lst[i])\n",
    "        return m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        points.sort(key = lambda x:x[0])\n",
    "        res = 0\n",
    "        for i in range(len(points) - 1):\n",
    "            res = max(res, points[i+1][0] - points[i][0])\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        points.sort(key=lambda x: x[0])\n",
    "        ma = 0\n",
    "        for index in range(1,len(points)):\n",
    "            ma = max(points[index][0] - points[index - 1][0], ma)\n",
    "           \n",
    "        return ma"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        x_list = sorted([p[0] for p in points])\n",
    "        return max([b-a for a, b in zip(x_list[:-1], x_list[1:])])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        points.sort(key=lambda x:x[0])\n",
    "        result = 0\n",
    "        for i in range(1,len(points)):\n",
    "            result = max(result, points[i][0]-points[i-1][0])\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        all_x = sorted(x for x, _ in points)\n",
    "        return max(x2 - x1 for x1, x2 in pairwise(all_x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        points.sort(key = lambda x:x[0])\n",
    "        return max(b[0]-a[0] for a,b in pairwise(points))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        points=sorted(points,key=lambda  x:x[0])\n",
    "        maxx=0\n",
    "        for i in range(len(points)-1):\n",
    "            maxx=max(points[i+1][0]-points[i][0],maxx)\n",
    "        return maxx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        points.sort(key=lambda x: x[0])\n",
    "        small=0\n",
    "        for i in range(len(points)):\n",
    "            x1,y1=points[i-1]\n",
    "            x2,y2=points[i]\n",
    "            if x2-x1>small:\n",
    "                small=x2-x1\n",
    "        return small\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        width = []\n",
    "        for i in points:\n",
    "            width.append(i[0])\n",
    "        width.sort()\n",
    "        res = []\n",
    "        for i in range(1,len(width)):\n",
    "            res.append(width[i]-width[i-1])\n",
    "        return max(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        x=0\n",
    "        points.sort()\n",
    "        for i in range(len(points)):\n",
    "            if i>0:\n",
    "                d=points[i][0]-points[i-1][0]\n",
    "                if d>x:\n",
    "                    x=d\n",
    "        return x\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        points.sort(key=lambda x: x[0])\n",
    "        max = 0\n",
    "        for index in range(1,len(points)):\n",
    "            if(points[index][0] - points[index - 1][0] >max):\n",
    "                max = points[index][0] - points[index - 1][0]\n",
    "        \n",
    "        return max"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        points.sort()\n",
    "        mx = 0\n",
    "\n",
    "        for i in range(1, len(points)):\n",
    "            mx = max(points[i][0] - points[i - 1][0], mx)\n",
    "        \n",
    "        return mx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        res = []\n",
    "        for i in points:\n",
    "            res.append(i[0])\n",
    "        res.sort()\n",
    "        return max(res[i]-res[i-1] for i in range(1, len(res))) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        ans=0\n",
    "        lst=[]\n",
    "        for i in range(len(points)):\n",
    "            lst.append(points[i][0])\n",
    "        lst.sort()\n",
    "        for i in range(len(lst)-1):\n",
    "            ans=max(ans,lst[i+1]-lst[i])\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        lst1=[]\n",
    "        for i in points:\n",
    "            lst1.append(i[0])\n",
    "        lst2=sorted(lst1)\n",
    "        lst3=[]\n",
    "        if len(lst2)==1:\n",
    "            return 0\n",
    "        else:\n",
    "            for i in range(1,len(lst2)):\n",
    "                num=lst2[i]-lst2[i-1]\n",
    "                lst3.append(num)\n",
    "            lst4=sorted(lst3)\n",
    "            return lst4[len(lst4)-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        n=len(points)\n",
    "        if n<2:\n",
    "            return 0\n",
    "        l=list(map (lambda x:x[0],points))\n",
    "        l.sort()\n",
    "        ans=0\n",
    "        for i in range(1,len(l)):\n",
    "            ans=max(ans,l[i]-l[i-1])\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        ans = -1\n",
    "        l = []\n",
    "        for i in range(len(points)):\n",
    "            l.append(points[i][0])\n",
    "        l.sort()\n",
    "        # print(l)\n",
    "        for j in range(1,len(l)):\n",
    "            ans = max(l[j] - l[j - 1],ans)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        a = sorted([x[0] for x in points])\n",
    "        for i in range(len(a) - 1):\n",
    "            a[i] = a[i+1] - a[i]\n",
    "        del a[len(a) - 1]\n",
    "        a = sorted(a)\n",
    "        return a[len(a) - 1]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        nums = [x for x, _ in points]\n",
    "        n = len(nums)\n",
    "        mi, mx = min(nums), max(nums)\n",
    "        bucket_size = max(1, (mx - mi) // (n - 1))\n",
    "        bucket_count = (mx - mi) // bucket_size + 1\n",
    "        buckets = [[inf, -inf] for _ in range(bucket_count)]\n",
    "        for x in nums:\n",
    "            i = (x - mi) // bucket_size\n",
    "            buckets[i][0] = min(buckets[i][0], x)\n",
    "            buckets[i][1] = max(buckets[i][1], x)\n",
    "        ans = 0\n",
    "        prev = inf\n",
    "        for curmin, curmax in buckets:\n",
    "            if curmin > curmax:\n",
    "                continue\n",
    "            ans = max(ans, curmin - prev)\n",
    "            prev = curmax\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        nums = [x for x, _ in points]\n",
    "        n = len(nums)\n",
    "        mi, mx = min(nums), max(nums)\n",
    "        bucket_size = max(1, (mx - mi) // (n - 1))\n",
    "        bucket_count = (mx - mi) // bucket_size + 1\n",
    "        buckets = [[inf, -inf] for _ in range(bucket_count)]\n",
    "        for x in nums:\n",
    "            i = (x - mi) // bucket_size\n",
    "            buckets[i][0] = min(buckets[i][0], x)\n",
    "            buckets[i][1] = max(buckets[i][1], x)\n",
    "        ans = 0\n",
    "        prev = inf\n",
    "        for curmin, curmax in buckets:\n",
    "            if curmin > curmax:\n",
    "                continue\n",
    "            ans = max(ans, curmin - prev)\n",
    "            prev = curmax\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        n = len(points)\n",
    "        arr = [x for x,y in points]\n",
    "        mi, mx = min(arr), max(arr)\n",
    "        bucket_size = max(1, (mx-mi)//(n-1))\n",
    "        bucket_cnt = (mx-mi)//bucket_size + 1\n",
    "        buckets = [[inf, -inf] for _ in range(bucket_cnt)]\n",
    "        for x in arr:\n",
    "            i = (x-mi)//bucket_size\n",
    "            buckets[i][0] = min(buckets[i][0], x)\n",
    "            buckets[i][1] = max(buckets[i][1], x)\n",
    "        ans = 0\n",
    "        prev = inf \n",
    "        for a,b in buckets:\n",
    "            if a > b:\n",
    "                continue \n",
    "            ans = max(ans, a-prev)\n",
    "            prev = b  \n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        n = len(points)\n",
    "        arr = [x for x,y in points]\n",
    "        mi, mx = min(arr), max(arr)\n",
    "        bucket_size = max(1, (mx-mi)//(n-1))\n",
    "        bucket_cnt = (mx-mi)//bucket_size + 1\n",
    "        buckets = [[inf, -inf] for _ in range(bucket_cnt)]\n",
    "        for x in arr:\n",
    "            i = (x-mi)//bucket_size\n",
    "            buckets[i][0] = min(buckets[i][0], x)\n",
    "            buckets[i][1] = max(buckets[i][1], x)\n",
    "        ans = 0\n",
    "        prev = inf \n",
    "        for a,b in buckets:\n",
    "            if a > b:\n",
    "                continue \n",
    "            ans = max(ans, a-prev)\n",
    "            prev = b  \n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int:\n",
    "        a = {x for x,y in points}\n",
    "        b = list(a)\n",
    "        b.sort()\n",
    "        n = len(b)\n",
    "        ans = 0\n",
    "        for i in range(n-1):\n",
    "            ans = max(ans,b[i+1] - b[i])\n",
    "        return ans\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
